package com.neusoft.a312cxy.android18cxy.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.neusoft.a312cxy.android18cxy.Listener.OrderListener;
import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.model.ClubModel;

/**
 * Created by Young on 2017/11/6.
 */

public class OrderInfoActivity extends AppCompatActivity {

    private RadioGroup rg;
    private RadioButton WeChat,Alipay;

    private TextView name,price,intro;
    private EditText et_num,username,tel;
    private Button buy;
    private int userid;
    String participantname,course_price,notice,telephone,uname,Pay_type,course_id;
    SharedPreferences sp;
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        context=OrderInfoActivity.this;
        initViews();
        //reg_return.setOnClickListener(this);
        //add.setOnClickListener(this);
      //  reduce.setOnClickListener(this);
        buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                participantname = name.getText().toString();
                telephone = tel.getText().toString();


                ClubModel clubModel=new ClubModel();
                clubModel.signcourse(participantname,course_id,telephone,"1",Pay_type,course_price,notice,19,ordersucc);
            }
        });

    }

    OrderListener<String> ordersucc=new OrderListener<String>() {
        @Override
        public void onResponse(String bean) {
            if(bean!=null){
            Toast.makeText(OrderInfoActivity.this,"下单成功",Toast.LENGTH_SHORT).show();
                finish();
            }
            else {
                Toast.makeText(OrderInfoActivity.this,"下单失败",Toast.LENGTH_SHORT).show();


            }


        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(OrderInfoActivity.this,"请求失败",Toast.LENGTH_SHORT).show();


        }
    };



    public void initViews() {
        /*获取用户*/
/*        sp=context.getSharedPreferences("Userid",MODE_PRIVATE);
        userid=Integer.valueOf(sp.getString("user_id",null));
        telephone=sp.getString("user_tel",null);
        uname=sp.getString("user_name",null);*/
        /*获取活动名*/
        Intent intent=getIntent();
        course_id=intent.getStringExtra("courseid");
        participantname=intent.getStringExtra("participantname");
        course_price=intent.getStringExtra("course_price");
        notice=intent.getStringExtra("course_notice");
        name=(TextView)findViewById(R.id.name);
        username= (EditText) findViewById(R.id.user_name);
        price= (TextView) findViewById(R.id.price);
        tel= (EditText) findViewById(R.id.tel);
        intro= (TextView) findViewById(R.id.intro);
      //  allprice= (TextView) findViewById(R.id.count);
        //et_num=(EditText)findViewById(R.id.num) ;
      //  add=(ImageButton)findViewById(R.id.add);
      //  reduce=(ImageButton)findViewById(R.id.reduce);
        buy= (Button) findViewById(R.id.buy);
        rg=(RadioGroup) findViewById(R.id.radiogroup);
        WeChat=(RadioButton) findViewById(R.id.W_pay);
        Alipay=(RadioButton) findViewById(R.id.Z_pay);
      //  reg_return= (ImageView) findViewById(R.id.reg_return);
        name.setText(participantname);
        price.setText(course_price);
        intro.setText(notice);
        tel.setText(telephone);
        username.setText(uname);

        //allprice.setText((num*Integer.parseInt(course_price))+"(元)");
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                switch (i){
                    case R.id.W_pay:
                        Pay_type="微信支付";
                        break;
                    case R.id.Z_pay:
                        Pay_type="支付宝支付";
                        break;
                }
            }
        });
    }




}
